package jpa.repository;

import jpa.entity.Address;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.scheduling.annotation.Async;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.stream.Stream;

/**
 * Created by barton on 16-4-29.
 */
public interface AddressRepository extends CrudRepository<Address, Long> {
    @Async
    CompletableFuture<Address> findByZipCode(String zipCode);

    Slice<Address> findTop3ByZipCodeStartsWith(String zipCode, Pageable pageable);

    @Query("select a from Address a")
    Stream<Address> streamAllPaged(Pageable pageable);
}
